﻿using AutoMapper;
using HealthcareSystem.API.Write.APPLication.Commad.ChronicSignCommad;
using HealthcareSystem.Domain;
using MediatR;
using WeekExam.PassPort.ErrorCode;
using WeekExam.PassPort.Infrastructure.Interface;

namespace HealthcareSystem.API.Write.APPLication.CommadHandel.ChronicSignCommadHandel
{
    public class AddCSignCommadHandel : IRequestHandler<AddCSignCommad, ApiResult<int>>
    {
        private readonly IBaseRepository<ChronicSign> cSRepository;
        private readonly IMapper mapper;

        public AddCSignCommadHandel(IBaseRepository<ChronicSign> CSRepository,IMapper mapper)
        {
            cSRepository = CSRepository;
            this.mapper = mapper;
        }
        public async Task<ApiResult<int>> Handle(AddCSignCommad request, CancellationToken cancellationToken)
        {
            ApiResult<int> result=new ApiResult<int>();
            result.Code=ResultCode.Success;
            result.Message=ResultCode.添加成功.ToString();

            var list= mapper.Map<ChronicSign>(request);
            await cSRepository.AddAsync(list);

            return await Task.FromResult(result);

        }
    }
}
